<template>
    <div class="form-box">
        <el-row class="title">{{ questionFormInfo.name }}</el-row>
        <el-row class="tip">{{ questionFormInfo.remark }}</el-row>
        <!-- <el-row class="title">{{ questionFormInfo.createBy }} {{ questionFormInfo.createTime }}</el-row> -->
        <el-form ref="listForm" :model="listForm" :rules="listFormRules" label-width="100px">
            <el-row v-for="(item, index) in list" :key="item.questionId" class="text">
                <el-col :span="24" v-if="item.questionType == '1'">
                    <el-form-item :label="item.questionSort + '.' + item.questionName"
                        :prop="item.requiredFlag === '0' ? 'answer' + index : null">
                        <el-radio-group v-model="listForm['answer' + index]">
                            <el-radio v-for="dict in item.options" :key="dict.id" :label="dict.id">{{
                                dict.value }}</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="item.questionType == '2'">
                    <el-form-item :label="item.questionSort + '.' + item.questionName"
                        :prop="item.requiredFlag === '0' ? 'answer' + index : null">
                        <el-checkbox-group v-model="listForm['answer' + index]">
                            <el-checkbox v-for="dict in item.options" :key="dict.id" :label="dict.id">{{
                                dict.value }}</el-checkbox>
                        </el-checkbox-group>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="item.questionType == '3'">
                    <el-form-item :label="item.questionSort + '.' + item.questionName"
                        :prop="item.requiredFlag === '0' ? 'answer' + index : null">
                        <el-input size="mini" placeholder="请输入内容" v-model="listForm['answer' + index]">
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="item.questionType == '4'">
                    <el-form-item :label="item.questionSort + '.' + item.questionName"
                        :prop="item.requiredFlag === '0' ? 'answer' + index : null">
                        <el-input type="textarea" autosize placeholder="请输入内容" v-model="listForm['answer' + index]">
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="item.questionType == '5'">
                    <el-form-item :label="item.questionSort + '.' + item.questionName"
                        :prop="item.requiredFlag === '0' ? 'answer' + index : null">
                        <el-select v-model="listForm['answer' + index]" clearable>
                            <el-option v-for="dict in item.options" :key="dict.id" :label="dict.value"
                                :value="dict.id"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
    </div>
</template>

<script>
export default {
    name: "Formpreview",
    props: ["formPreviewList", "questionFormInfo"],
    data() {
        return {
            listForm: {},
            list: [],
            listFormRules: {},
        };
    },
    created() { },
    mounted() {
        console.log("this.formPreviewList", this.formPreviewList);
        this.list = [];
        this.formPreviewList.forEach((element, index) => {
            this.$set(this.listForm, 'answer' + index, element.answer)
            this.$set(this.listFormRules, 'answer' + index, [
                {
                    required: true,
                    message: "不能为空",
                    trigger: "blur",
                },
            ],)
            element.options = JSON.parse(element.options);
            element['answer' + index] = element.answer
            this.list.push(element);
        });
    },
    watch: {
        formPreviewList: function (newValue, oldValue) {
            this.list = [];
            newValue.forEach((element, index) => {
                this.$set(this.listForm, 'answer' + index, element.answer)
                this.$set(this.listFormRules, 'answer' + index, [
                    {
                        required: true,
                        message: "不能为空",
                        trigger: "blur",
                    },
                ],)
                element.options = JSON.parse(element.options);
                element['answer' + index] = element.answer
                this.list.push(element);
            });
            console.log(2222222, this.listForm)
        },
    },
    methods: {
        /**questionType 1 单选 2多选 3填空 4下拉 */
    },
};
</script>
<style scoped>
.form-box {
    border: 1px solid #000;
    padding: 25px;
    background-color: #f2f2f2;
    color: #000;
}

.title {
    text-align: center;
    font-size: 20px;
    margin-bottom: 15px;
}

.tip {
    text-align: center;
    font-size: 16px;
    margin-bottom: 15px;
}

.text {
    font-size: 18px;
}

::v-deep .el-radio__label {
    white-space: wrap;
    font-size: 16px;
}

::v-deep .el-checkbox__label {
    font-size: 16px;
    white-space: wrap;
}

::v-deep .el-input--mini {
    font-size: 16px;
}

::v-deep .el-textarea {
    font-size: 16px;
}

::v-deep .el-form-item__label {
    font-size: 16px;
    float: none;
}

::v-deep .el-form-item__content {
    margin-left: 0 !important;
}
</style>
